package com.zhoutao123.hephaestus.controller;

import com.zhoutao123.hephaestus.object.bussiness.VBlog;
import com.zhoutao123.hephaestus.object.bussiness.VBlogs;
import com.zhoutao123.hephaestus.object.transport.BlogTO;
import com.zhoutao123.hephaestus.object.transport.PageBean;
import com.zhoutao123.hephaestus.service.BlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/blog")
@Api(tags = "文章相关接口")
public class BlogController {

  @Autowired BlogService blogService;

  @GetMapping()
  @ApiOperation(value = "获取文章列表")
  public VBlogs getListByKey(String key, PageBean pageInfo) {
    return blogService.getByPageInfo(key, pageInfo);
  }

  @GetMapping(value = "/{blogId}")
  @ApiOperation(value = "获取指定文章")
  public VBlog getListById(@PathVariable("blogId") String articleId) {
    return blogService.getById(articleId, true);
  }

  @GetMapping("/latest")
  public VBlogs getLatestBLog(@RequestParam Integer number) {
    return blogService.getLatestWithParam(number);
  }

    @PatchMapping
    @ApiOperation("发布文章或者更新文章")
    public VBlog publishBlog(@RequestBody BlogTO blogTO) {
        return blogService.createOrUpdateBlog(blogTO);
    }
}
